#include <iostream>
#include <stdlib.h>
#include <limits>
#include <stdio.h>
#include <assert.h>

#define MAXNUM 1000
//#define mydebug 
using namespace std;

struct JS {
    int dj;
    int pj;
    int used;
};

void DP(JS* js, int n, int m);
int dpp(JS*js, int n, int m, int si, int cm);
int diff(JS* js, int n);
int sum(JS* js, int n);
int count(JS* js, int n);
int get_prosecution(JS* js, int n);
int get_defence(JS* js, int n);
JS fjs[MAXNUM];
int fd = numeric_limits<int>::max();
int fs = numeric_limits<int>::min();
int lc = 1;

int main() {
    int n, m;
    JS js[MAXNUM];
    cin >> n >> m;
    while (!(n == 0 && m == 0)) {
        printf("n: %d, m: %d\n", n, m);
        for (int i = 0; i < n; i++) {
            int d, p;
            cin >> d >> p;
            printf("d: %d, p:%d\n", d,p);
            js[i].pj = d;
            js[i].dj = p;
            js[i].used = 0;
        }
        DP(js, n, m);
        cin >> n >> m;
        assert( n < MAXNUM);
        lc++;
    }
    return 0;
}

void DP(JS* js, int n, int m) {
    fd = numeric_limits<int>::max();
    fs = numeric_limits<int>::min();
    dpp(js, n, m, 0, m);
    printf("n: %d m: %d\n", n, m);
    int fp = get_prosecution(fjs, n);
    int fd = get_defence(fjs, n);
    cout << "Jury #" << lc << endl;
    cout << "Best jury has value " << fp << " for prosecution and value " << fd << " for defence:" << endl;
    for (int i = 0; i < n; i++) {
        if (fjs[i].used) {
            cout << " " << i + 1;
        }
    }
    cout << endl << endl;
}

int dpp(JS* js, int n, int m, int si, int cm) {
    //    mydebug("n: %d, m:%d, si:%d, cm: %d\n", n, m, si, cm);
    if (cm == 0) {
        if (count(js, n) != m) {
            return 0;
        } else {
            int d = diff(js, n);
            //            mydebug("d is %d \n", d);
            if (d < fd) {
                fd = d;
                fs = sum(js, n);
                memcpy(fjs, js, sizeof (JS)* MAXNUM);
            } else if (d == fd) {
                if (sum(js, n) > fs) {
                    fs = sum(js, n);
                    memcpy(fjs, js, sizeof (JS)* MAXNUM);
                }
            }
        }
        return 0;
    }
    for (int i = si; i < n - cm + 1; i++) {
        js[i].used = 1;
        dpp(js, n, m, i + 1, cm - 1);
        js[i].used = 0;
    }
    return 1;
}

int diff(JS* js, int n) {
    int d = 0, p = 0;
    for (int i = 0; i < n; i++) {
        if (js[i].used) {
            d += js[i].dj;
            p += js[i].pj;
        }
    }
    return abs(d - p);
}

int sum(JS* js, int n) {
    int s = 0;
    for (int i = 0; i < n; i++) {
        if (js[i].used) {
            s += (js[i].dj + js[i].pj);
        }
    }
    return s;
}

int count(JS* js, int n) {
    int s = 0;
    for (int i = 0; i < n; i++) {
        if (js[i].used) {
            s++;
        }
    }
    return s;
}

int get_prosecution(JS* js, int n) {
    int s = 0;
    for (int i = 0; i < n; i++) {
        if (js[i].used) {
            s += js[i].pj;
        }
    }
    return s;
}

int get_defence(JS* js, int n) {
    int s = 0;
    for (int i = 0; i < n; i++) {
        if (js[i].used) {
            s += js[i].dj;
        }
    }
    return s;
}